package com.ttianjun.spring.controller;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.UUID;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.ttianjun.spring.model.ClassInfo;
import com.ttianjun.spring.model.EcpNews;
import com.ttianjun.spring.service.ClassInfoService;
import com.ttianjun.spring.service.EcpNewsService;

/**
 * Created by djei on 2015-04-22.
 */
@Controller
public class HelloWorldController {
    @Autowired
    private ClassInfoService classInfoService;
    
    @Autowired
    private EcpNewsService ecpNewsService;

    @RequestMapping("/")
    public String hello(@RequestParam(value="name", required=false, defaultValue="World") String name, Model model) {
    	//List<ClassInfo> list = classInfoService.getClassInfoByStudentcount(7);
    	EcpNews ecpNews = new EcpNews();
    	Date pubTime =  new Date();
    	String id = UUID.randomUUID().toString();
    	ecpNews.setId(id);
    	ecpNews.setContent("content");
    	ecpNews.setTitle("title");
    	ecpNews.setType("NEWS | LAWS_AND_REGULATIONS");
    	ecpNews.setSummary("summary");
    	ecpNews.setPubTime(pubTime);
    	ecpNews.setKeyWord("资讯");
    	ecpNewsService.insertEcpNews(ecpNews);
    	List<ClassInfo> list = new ArrayList<>();
    	for (int i=0;i<7;i++) {
    		ClassInfo classInfo = new ClassInfo();
    		classInfo.setHeadteacher("teacher"+i);
    		classInfo.setId(Short.valueOf(String.valueOf(i)));
    		classInfo.setName(name);
    		classInfo.setStudentcount(Byte.valueOf(String.valueOf(i)));
    		list.add(classInfo);
		}
    	
        model.addAttribute("list", list);
        return "index";
    }
}
